﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Bll;
using Runda.EShop.Common.Entity;
using Runda.EShop.Common.Utility;

namespace Runda.EShop.SaaS.SysManage
{
    public partial class ChangePassword : BasePage
    {
        public Guid UserID
        {
            get
            {
                if (Request.QueryString["UserID"] != null)
                {
                    return new Guid(Request.QueryString["UserID"]);
                }
                return Guid.Empty;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["UserID"] != null)
                {
                    SystemBll bll = new SystemBll();
                    SysUserEntity entity = bll.Get<SysUserEntity>(UserID);
                    if (entity != null)
                    {
                        txtUserName.Text = entity.UserName;
                        txtAccount.Text = entity.Account;
                    }
                }
            }
        } 

        protected void lnkbtnSave_Click(object sender, EventArgs e)
        {
            if (txtNewPwd.Text.Trim() != txtConfirmPwd.Text.Trim())
            {
                ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('两次密码不一致!');", true);
                return;
            }
            SystemBll bll = new SystemBll();
            OperateResult result = bll.ChangePassword(UserID, System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPwd.Text.Trim(), "MD5"));
            if (! result.IsSuccess)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('" + result.Message + "!');", true);
                return;
            }
            ClientScript.RegisterStartupScript(this.GetType(), "success", "parent.$.ligerDialog.hide();", true);
        }
    }
}